home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / RWSUB2.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  2KB  |  86 lines

  1. ; RWSUB2 - disk read/write subroutine for compiled BASIC
  2. ; Copyright 1983 Data Base Decisions
  3. ;
  4. ; Note: This routine requires DOS 2.00 or later!
  5. ;
  6. ; CALL RWSUB2(FIL$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
  7. ; FIL$ is the file name in ASCIIZ format
  8. ; FUNC% indicates reading (=0), writing (=1), or creating (and writing =2)
  9. ; SBYTELO% is the low part of the starting byte
  10. ; SBYTEHI% is the high part of the starting byte (HI*65536+LO)
  11. ; NOBYTES% is the number of bytes to be read/written
  12. ; DTASEG% is the segment to be read into or written from
  13. ; RETCODE% is an error return code (non-zero if an error occurred)
  14.  
  15. skip    equ 2            ; 2 for compiled, 1 for interpretive
  16.  
  17. cseg    segment para public 'code'
  18. public    rwsub2
  19. rwsub2    proc far
  20.     assume cs:cseg,ds:nothing,ss:nothing,es:nothing
  21.  
  22.     push bp
  23.     mov bp,sp
  24.  
  25.                 ; open the file
  26.     mov si,[bp+18]        ; point to FIL$
  27.     add si,skip
  28.     mov dx,[si]        ; point to file name
  29.     mov si,[bp+16]        ; point to FUNC%
  30.     mov al,[si]        ; get access code in al
  31.     mov ah,3dh
  32.     cmp al,2        ; create?
  33.     jnz p010        ; no
  34.     dec ah
  35.     mov cx,0        ; clear attributes
  36. p010:    int 21h         ; open the file
  37.     jc p030         ; error?
  38.  
  39.                 ; set the file pointer
  40.     mov bx,ax        ; get the handle
  41.     mov si,[bp+12]        ; point to SBYTEHI%
  42.     mov cx,[si]        ; put it in cx
  43.     mov si,[bp+14]        ; point to SBYTELO%
  44.     mov dx,[si]        ; put it in dx
  45.     mov ah,42h        ; move file read/write pointer
  46.     mov al,0        ; method 0 - offset from beginning of file
  47.     int 21h         ; position in the file
  48.     jc p030         ; error?
  49.  
  50.                 ; read/write the file
  51.     mov si,[bp+10]        ; point to NOBYTES%
  52.     mov cx,[si]        ; number of bytes to read/write
  53.     mov si,[bp+16]        ; point to FUNC%
  54.     mov ah,[si]        ; 0 for read, 1 for write
  55.     cmp ah,2        ; create?
  56.     jnz p020        ; no
  57.     dec ah            ; yes - make it a write
  58. p020:    add ah,3fh        ; setup interrupt function
  59.     push ds
  60.     mov si,[bp+8]        ; point to DTASEG%
  61.     mov dx,[si]
  62.     mov ds,dx        ; now in ds
  63.     xor dx,dx        ; ds:dx contains DTA
  64.     int 21h         ; read/write the file
  65.     pop ds            ; get orig ds
  66.     jc p030         ; error?
  67.     mov si,[bp+10]        ; point to NOBYTES%
  68.     mov [si],ax        ; save bytes read/written
  69.  
  70.                 ; close the file
  71.     mov ah,3eh
  72.     int 21h         ; close the file
  73.     jnc p040        ; no error
  74.  
  75. p030:                ; error handler
  76.     mov si,[bp+6]        ; point to RETCODE%
  77.     mov [si],ax        ; save the error
  78.  
  79. p040:                ; return to caller
  80.     pop bp
  81.     ret 14
  82.  
  83. rwsub2    endp
  84. cseg    ends
  85.     end
  86.